﻿// Copyright (c)  MOKEYISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

using System;

namespace NSQL.Expressions
{
    public class GroupExpression : BaseExpression, IGroupExpression
    {
        public ILogicalExpression Left { get; set; }
        public ILogicalExpression Right { get; set; }

        public GroupOperator Operator { get; set; }

        public GroupExpression()
        {
        }

        public GroupExpression(ILogicalExpression left, ILogicalExpression right, GroupOperator op)
        {
            Left = left;
            Right = right;
            Operator = op;
        }

        public override T Accept<T>(IExpressionVisitor<T> visitor) => visitor.Visit(this);

        public static GroupOperator ParseOperator(string op)
        {
            if (Enum.TryParse(op, out GroupOperator result))
            {
                return result;
            }

            throw new Exception("UnExpected group operator.expecting {And, Or}");
        }
    }

    public enum GroupOperator
    {
        And,
        Or
    }
}